From 4cd9926550267236f10e82972dc3b24ab55ce2a8 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Wed, 5 Apr 2006 18:16:10 +0000 Subject: [PATCH] Test the result of acos() for possible errors (gcdist). git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1816 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/grtcirc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gpsbabel/grtcirc.c b/gpsbabel/grtcirc.c index 3676eeaa5..69d1c501d 100644 --- a/gpsbabel/grtcirc.c +++ b/gpsbabel/grtcirc.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#include #include #include "defs.h" @@ -51,7 +52,13 @@ double tomiles( double rads ) { } double gcdist( double lat1, double lon1, double lat2, double lon2 ) { - return acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2)); + double res; + res = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2)); + if (errno == EDOM) { /* Math argument out of domain of function */ + errno = 0; + return 0; + } + return res; } double linedist(double lat1, double lon1, -- 2.30.2